<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('单历史版本列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>版本号：</p>
                            <input type="hidden" name="layoutId" th:value="${layoutId}" id="layoutId">
                            <input type="text" name="versionNum"/>
                        </li>
                        <li>
                            <p>发布状态：</p>
                            <select name="versionStatus" th:with="type=${@dict.getType('form_version_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="add()" shiro:hasPermission="form:version:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="form:version:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="form:version:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="form:version:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-success" onclick="design()">
                <i class="fa fa-download"></i> 设计
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('form:version:edit')}]];
    var removeFlag = [[${@permission.hasPermi('form:version:remove')}]];
    var versionStatusDatas = [[${@dict.getType('form_version_status')}]];
    var prefix = ctx + "form/version";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "单历史版本",
            columns: [{
                radio: true
            },
                {
                    field: 'versionId',
                    title: 'null',
                    visible: false
                },
                {
                    field: 'layoutName',
                    title: '表单名称'
                },
                {
                    field: 'versionNum',
                    title: '版本号'
                },
                {
                    field: 'versionStatus',
                    title: '发布状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(versionStatusDatas, value);
                    }
                },
                {
                    field: 'createBy',
                    title: '创建人'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'updateBy',
                    title: '更新人'
                },
                {
                    field: 'updateTime',
                    title: '更新时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="preview(\'' + row.versionId + '\')">预览</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="design(\'' + row.versionId + '\')">设计</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.versionId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.versionId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function design(versionId) {
        if(versionId==undefined){
            var selected = $.table.selectFirstColumns();
            if (selected == "") {
                $.modal.msgError("请选择");
                return;
            }
            versionId=selected
        }

        window.open(ctx + "form/display/design/"+versionId)
    }
    function preview(versionId){
        var url=ctx + "form/display/preview/0/"+versionId+"/0";
        $.modal.openTab("预览表单/"+versionId, url);
    }
    function add(){
        $.operate.add($("#layoutId").val());
    }
</script>
</body>
</html>